# -*- coding: utf-8 -*-
"""
@author:  yinbing.li(yinbing.li@zillnk.com)
@version: 1.0.0
@file:    leetcode977_有序数组的平方.py
@time:    2023/3/8 11:30
"""
from typing import List


class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        return sorted([i ** 2 for i in nums])

    def sortedSquares11111(self, nums: List[int]) -> List[int]:
        i, j = 0, len(nums) - 1
        result = [0] * len(nums)
        pos = len(nums) - 1
        while i <= j:
            i2, j2 = nums[i] ** 2, nums[j] ** 2
            if i2 < j2:
                result[pos] = j2
                j -= 1
            else:
                result[pos] = i2
                i += 1
            pos -= 1
        return result

s =Solution()
print(s.sortedSquares11111([-4, -1, 0, 3, 10]))